import { request } from "@/network/request";
// 样例,会了就删了
export function getMessage(goods) {
  return request({
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/home/data", // url地址后缀完整的在外部
    params: {
      goodsId: goods.goodsId,
      goodsTitle: goods.goodsTitle,
      goodsInfo: goods.goodsInfo,
      price: Number.parseFloat(goods.price),
      goodsImg: goods.goodsImg,
      goodsNum: goods.goodsNum
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function getMsg(id, phone) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/msg/send", // url地址后缀完整的在外部
    params: {
      id: id,
      mobile: phone
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function CheckMsg(phone) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/getmsg", // url地址后缀完整的在外部
    params: {
      mobile: phone
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function Reg(code, mobile, nickname, password, username) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/register",
    params: {
      code: code,
      mobile: mobile,
      nickname: nickname,
      password: password,
      username: username
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}

export function Login(password, username) {
  console.log(password, username);
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/login",
    params: {
      password: password,
      username: username
    },
    headers: {
      // 头文件封装
      // sAuthorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "content-type": "multipart/form-data"
      /* "Content-Type": "application/json;charset=UTF-8" */
    }
  });
}

export function accountCheck(username) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/yzun",
    params: {
      username: username
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function useAccount(username) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/obtainName",
    params: {
      username: username
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function phoneChecked(mobile) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/yzum",
    params: {
      mobile: mobile
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
export function modify(username, password) {
  return request({
    baseURL: "/api",
    method: "POST", // 发送方法 GET POST DELETE PUT
    url: "/sys/lr/modify",
    params: {
      password: password,
      username: username
    },
    headers: {
      // 头文件封装
      Authorization: sessionStorage.getItem("userToken"),
      // 格式设置
      "Content-Type": "application/json"
    }
  });
}
//防抖函数
export function debounce(func, wait = 200) {
  let timeout = null;
  return function() {
    let context = this;
    let args = arguments;
    if (timeout) clearTimeout(timeout);
    timeout = null;
    timeout = setTimeout(() => {
      func.apply(context, args);
    }, wait);
  };
}
